<template>
  <div class="blog-item" @click="$emit('click')">
    <div class="blog-content">
      <h3 class="blog-title">{{ data.title }}</h3>
      <p class="blog-summary">{{ data.summary }}</p>
      <div class="blog-meta">
        <div class="author-info">
          <img :src="data.author.avatar" :alt="data.author.name" class="author-avatar" />
          <span class="author-name">{{ data.author.name }}</span>
        </div>
        <div class="blog-stats">
          <span class="blog-views">
            <van-icon name="eye-o" />
            {{ formatNumber(data.views) }}
          </span>
          <span class="blog-likes">
            <van-icon name="like-o" />
            {{ formatNumber(data.likes) }}
          </span>
        </div>
      </div>
    </div>
    <div v-if="data.cover" class="blog-cover">
      <img :src="data.cover" :alt="data.title" />
    </div>
  </div>
</template>

<script setup>
import { formatNumber } from '../../utils/common'

const props = defineProps({
  data: {
    type: Object,
    required: true
  }
})

defineEmits(['click'])
</script>

<style lang="scss" scoped>
.blog-item {
  display: flex;
  padding: 12px;
  background-color: var(--background-color-light);
  border-radius: 8px;
  box-shadow: var(--box-shadow);
  cursor: pointer;
  transition: transform 0.2s;
  
  &:active {
    transform: scale(0.98);
  }
  
  .blog-content {
    flex: 1;
    overflow: hidden;
    margin-right: 12px;
    
    .blog-title {
      font-size: 16px;
      font-weight: 500;
      color: var(--text-color);
      margin-bottom: 8px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    
    .blog-summary {
      font-size: 14px;
      color: var(--text-color-secondary);
      margin-bottom: 12px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
    }
    
    .blog-meta {
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 12px;
      color: var(--text-color-tertiary);
      
      .author-info {
        display: flex;
        align-items: center;
        
        .author-avatar {
          width: 20px;
          height: 20px;
          border-radius: 50%;
          margin-right: 4px;
        }
      }
      
      .blog-stats {
        display: flex;
        
        .blog-views, .blog-likes {
          display: flex;
          align-items: center;
          margin-left: 8px;
          
          .van-icon {
            margin-right: 2px;
          }
        }
      }
    }
  }
  
  .blog-cover {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
    
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
}
</style> 